﻿using System.Globalization;
using System.Modules.Constants.FormattingTypes;
using System.Security.Cryptography;
using System.Text;

namespace System.Modules.Extensions
{
    /// <summary>
    /// Include All Hash Extensions
    /// </summary>
    public static class HashExtensions
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static byte[] GetHashValue(this string value)
        {
            return string.IsNullOrEmpty(value) ? null : MD5.Create().ComputeHash(Encoding.Unicode.GetBytes(value));
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ConvertHashToString(this byte[] value)
        {
            if (value == null) return null;
            var builder = new StringBuilder("0x");
            for (var i = 0; i < value.Length; i++)
            {
                //StandardNumericFormat.ge
                builder.Append(value[i].ToString("X2", CultureInfo.InvariantCulture));
            }
            return builder.ToString();
        }
    }
}
